package com.pan.test.socket.example02;

import java.io.*;
import java.net.InetAddress;
import java.net.Socket;

/**
 * 字符流
 *
 */
public class MyClient02 {
    public static void main(String[] args) throws Exception {

        InetAddress localHost = InetAddress.getLocalHost();

        Socket socket = new Socket(localHost, 11451);
        String msg = "hello server 字符流";
        OutputStream outputStream = socket.getOutputStream();
        BufferedWriter bufferedWriter = new BufferedWriter(new OutputStreamWriter(outputStream));
        bufferedWriter.write(msg);
        bufferedWriter.newLine();//一定要有这个，和对面readLine配套使用
        bufferedWriter.flush();
        socket.shutdownOutput();



        InputStream inputStream = socket.getInputStream();
        BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream));
        String r_msg = bufferedReader.readLine();
        System.out.println(r_msg);


        bufferedWriter.close();
        bufferedReader.close();
        socket.close();


    }
}
